package com.etoak.train.controller;

import com.etoak.train.req.MemberLoginReq;
import com.etoak.train.req.MemberRegisterReq;
import com.etoak.train.req.MemberSendCodeReq;
import com.etoak.train.resp.CommonResp;
import com.etoak.train.resq.MemberLoginResp;
import com.etoak.train.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author by 孙有泽
 * @Date 2025/5/9 21:27
 * @Description 会员controller
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService memberService;
    /*
     * @author 孙有泽
     * @date 2025/5/10 13:08
     * @description 统计会员数量
     */
    @GetMapping("/count")
    public CommonResp<Integer> test(){
        CommonResp<Integer> objectCommonResp = new CommonResp<>();
        Integer count = memberService.count();
        objectCommonResp.setContent(count);
        return objectCommonResp;
    }
    /*
     * @author 孙有泽
     * @date 2025/5/10 10:57
     * @description 会员注册
     */
    @PostMapping("register")
    public CommonResp<Long> register(@Valid MemberRegisterReq memberRegisterReq){
        CommonResp<Long> objectCommonResp = new CommonResp<>();
        long register = memberService.register(memberRegisterReq);
        objectCommonResp.setContent(register);
        return objectCommonResp;
    }
    /*
     * @author 孙有泽
     * @date 2025/5/10 10:57
     * @description 发送短信验证码
     */
    @PostMapping("/send-code")
    public CommonResp<Long> sendCode(@Valid MemberSendCodeReq req){
        memberService.sendCode(req);
        return new CommonResp<>();
    }
    /*
     * @author 孙有泽
     * @date 2025/5/10 11:15
     * @description 会员登录
     */
    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq req) {
        MemberLoginResp resp = memberService.login(req);
        return new CommonResp<>(resp);
    }

}
